<route lang="json5" type="page">
{
  layout: 'default',
  style: {
    navigationStyle: 'custom',
  },
}
</route>

<template>
  <view class=""></view>
</template>

<script lang="ts" setup>
import { useToast } from 'wot-design-uni'
import { getHomeUrl } from '@/service/index/login'
import { useUserStore } from '@/store'

const userStore = useUserStore()
const toast = useToast()

onLoad(async (options) => {
  toast.loading({
    msg: '登录中',
    direction: 'vertical',
  })
  if (options.code) {
    userStore
      .login(options.code)
      .then(() => {
        const optionsPath = window.sessionStorage.getItem('optionsPath')
        if (optionsPath) {
          window.sessionStorage.removeItem('optionsPath')
          // uni.redirectTo({ url: optionsPath })
          window.location.replace(optionsPath)
        }
        toast.close()
      })
      .catch((error) => {
        console.log(error)
      })
  } else {
    const { data } = await getHomeUrl()
    // uni.redirectTo({ url: data })
    window.location.replace(data as string)
  }
})
</script>

<style lang="scss" scoped>
//
</style>
